package model;

import java.math.BigDecimal;

public class FrequencyPair implements Comparable{
	private double num;
	private BigDecimal freq;
	
	public FrequencyPair(int num) {
		this.num = num;
		freq = BigDecimal.ZERO;
	}
	
	public FrequencyPair(double num, BigDecimal freq){
		this.num = num;
		this.freq = BigDecimal.valueOf(Math.round(freq.doubleValue()));
	}
	
	public void setNum(double num){
		this.num = num;
	}
	
	public void setFrequency(BigDecimal l) {
		freq = BigDecimal.valueOf(Math.round(l.doubleValue()));
	}
	
	public BigDecimal getFrequency() {
		return freq;
	}
	
	public void addOne() {
		freq = freq.add(BigDecimal.ONE);
	}
	
	public void addCount(BigDecimal l) {
		freq = freq.add(BigDecimal.valueOf(Math.round(l.doubleValue())));
	}
	
	public String toString() {
		String toPrint = "(";
		
		if (num == Math.floor(num))
			toPrint += (long)(num);
		else toPrint += num;
		
		toPrint += ", ";
		
		if (Math.floor(freq.doubleValue()) == freq.doubleValue())
			toPrint += (long)(Math.round(freq.doubleValue()));
		else toPrint += freq;
		
		return toPrint + ")";
	}
	
	public int getNum(){
		return (int)num;
	}
	
	public double getNumAsDouble(){
		return num;
	}
	
	public FrequencyPair getCopy(){
		return new FrequencyPair(num, freq);
	}

	@Override
	public int compareTo(Object arg0) {
		FrequencyPair other = (FrequencyPair) arg0;
		double diff = num - other.num;
		if(diff < 0)
			return -1;
		
		if(diff > 0)
			return 1;
		
		return 0;
	}
}